package in.co.codedoc.events.tests;

import static org.junit.Assert.*;
import org.junit.Test;

import in.co.codedoc.event.EventHandler;
import in.co.codedoc.event.SynchronousEventRegistry;
import in.co.codedoc.ioc.IOCContainer;
import in.co.codedoc.tests.JUNitTestBase;

public class SyncEventTests
	extends JUNitTestBase
{
	public static class TestEvent0
	{
		
	}
	
	public static class TestEvent1
		extends TestEvent0
	{
		
	}
	
	public static class TestEvent2
	{
		
	}
	
	public static class TestEventHandler
	{
		@EventHandler
		public void Foo(TestEvent0 te)
		{
			numTE0++;			
		}

		@EventHandler
		public void Foo(TestEvent1 te)
		{
			numTE1++;
		}
		
		@EventHandler
		public void Foo(TestEvent2 te)
		{
			numTE2++;
		}
		
		public int numTE0 = 0;
		public int numTE1 = 0;
		public int numTE2 = 0;
	}
	
	@Test
	public void TestBasicOps()
	{
		SynchronousEventRegistry ser
			= IOCContainer.Lookup(SynchronousEventRegistry.class);
	
		TestEventHandler teh = new TestEventHandler();
		ser.Register(TestEvent0.class, teh);
		ser.Register(TestEvent1.class, teh);
		ser.Register(TestEvent2.class, teh);
		
		ser.Dispatch(new TestEvent0());
		ser.Dispatch(new TestEvent1());
		ser.Dispatch(new TestEvent2());
		
		assertEquals(2,teh.numTE0);
		assertEquals(1,teh.numTE1);
		assertEquals(1,teh.numTE2);
	}
}
